package main

//gin代码示例
import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func hello(c *gin.Context) {
	username := c.Param("username")
	address := c.Param("address")
	c.JSON(http.StatusOK, gin.H{
		"username": username,
		"address":  address,
	})
}

type User struct {
	UserName string
	Password string
}

func userInfo(c *gin.Context) {
	var u User
	c.ShouldBind(&u)
	c.JSON(http.StatusOK, gin.H{
		"username": u.UserName,
		"password": u.Password,
	})

}

func main() {
	r := gin.Default()

	r.GET("/hello/:username/:address", hello)

	r.POST("/userInfo", userInfo)

	//请求重定向
	r.GET("/index", func(c *gin.Context) {
		c.Redirect(http.StatusMovedPermanently, "https://www.baidu.com")
	})

	r.Run(":8090")

}
